<?php
include 'common.php';

$db = new DB($config['db_host'], $config['db_name'], $config['db_user'], $config['db_pass']);
$req = file_get_contents('php://input');
$ret = json_decode($req);

// echo $ret->username;

switch($_SERVER['REQUEST_METHOD']){
    case 'POST':
        $sql = 'insert into `contacts` (`username`, `email`, `description`) values ("'. $ret->username .'", "'. $ret->email .'", "'. $ret->description .'")';
        $db->query($sql);
        echo 'insert data';
        break;
    case 'GET':
        $sql = 'select * from `contacts`';
        $ret = $db->get_results($sql);
        echo json_encode($ret);
        break;
    case 'PUT':
        echo 'put...';
        break;
    case 'DELETE':
        echo 'delete...';
        break;
}
